<template>
	<view>
		 <view class="posts-container">
		<finditem v-for="item in showdata.result" :key="item.id" :obj="item"></finditem>
		<!-- 传入文章对象 -->
		<view class="notfind" v-show="showdata.result.length === 0">{{showdata.message}}</view>
		</view>
	</view>
</template>

<script>
	import finditem from "@/component/find/find_item.vue"
	import myquest from "@/untils/request.js"
	export default{
		components:{
			finditem
		},
		data(){
			return{
				queryKey:"",
				showdata:{
					result:[],
					message:""
				}
			}
		},
		methods:{
			search(){
				console.log("开始搜索了");
				myquest.search(this.$store.state.token,this.queryKey)
				.then(r=>{
					console.log(r);
					if(r.statusCode===200){
						if(r.data.code === 0){
							this.showdata.result = r.data.data
						}else{
							this.showdata.message = r.data.message
						}
					}
				}).then(r=>{
					uni.hideLoading()
				})
				.catch(err=>{
					uni.showToast({
						title:"网络错误",
						icon:"error"
					})
					uni.hideLoading()
				})
			}
		},
		onLoad(option) {
			uni.showLoading({
				title:"正在加载中···"
			})
			this.queryKey = option.key
			console.log(this.queryKey);  
			//发送搜索请求，并且展示 = 编辑页面
			this.search()
		},
		onUnload() {
			console.log("消失了");
		}
	}
</script>

<style>
	.posts-container {
	  padding: 12px;
	}
	
	.notfind{
		font-size: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>